<?php
session_start ();
include_once 'library/config.php';
include_once 'library/query.php';
//include_once 'library/utils.php';
//include_once 'library/ftp.php';

//if ($CONFIG_language == "English" || $CONFIG_language == "Portuguese") {
//  ini_set( 'default_charset', 'ISO-8859-1' );
//}

$db = new db_class();
if (!$db->connect($CONFIG_host, $CONFIG_user, $CONFIG_pass, $CONFIG_db)) {
  $db->print_last_error();
}
if (!$db->select_db()){
  die("Banco de dados não encontrado!");
}

//URL treatment
if (!isset($GET_page)) {
  $GET_page = "login";
} elseif(preg_match("/http|ftp|https|www|wget/", $GET_page) || !is_file($GET_page.".php")) {
  $GET_page = "error404";
}

//Remember me
//if (isset($_COOKIE["userinfoid"])) {
//  $userinfoid = $_COOKIE["userinfoid"]; 
//}
//if (isset($_COOKIE["userinfopw"])) {
//  $userinfopw =  $_COOKIE["userinfopw"];  
//}

//if (isset($userinfoid) && isset($userinfopw) && !isset($_SESSION['loggeduser']['id'])) {
//  $result = $db->select("SELECT acc_id FROM useraccount WHERE acc_id LIKE '".$userinfoid."' AND acc_password LIKE '".$userinfopw."' //LIMIT 1");
//  $result = $db->get_row($result);
//  if ($result != "") {
//    $_SESSION['loggeduser']['id'] = $userinfoid;  
//    $_SESSION['loggeduser']['accesslevel'] = $result['acc_accesslevel'];
//  } else {
//    setcookie("userinfoid", "", time()-3600);
//    setcookie("userinfopw", "", time()-3600);
//  }
//}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title><?php print $CONFIG_name; ?></title>
<link rel="shortcut icon" href="images/PMMlogo.ico.png" type="image/png"/>
<link rel="stylesheet" type="text/css" href="css/common.css">
<link rel="stylesheet" type="text/css" href="css/eggplant/jquery-ui-1.8.4.custom.css" />
<?php
if (!isset($GET_service)) {
  echo '<link rel="stylesheet" type="text/css"  href="css/'.$GET_page.'.css">';
}
?>

<!--<script type="text/javascript" src="js/jquery-1.4.2.min.js">
        </script>-->
<script type="text/javascript" src="js/jquery-1.8.3.js">
        </script>
<script type="text/javascript" src="js/jquery.extras.js">
        </script>
<script type="text/javascript" src="js/jquery.timeago.js">
        </script>
<script type="text/javascript" src="js/jquery-ui-1.8.4.custom.min.js">
        </script>
<script type="text/javascript" src="js/utils.js">
        </script>
<?php
if (!isset($GET_service)) {
  echo '<script type="text/javascript" src="js/'.$GET_page.'.js"></script>';
}
?>
<script>
//    $(document).ready(function() {
//        wtd.user = {
//          acc_id: <?php //echo $_SESSION['loggeduser']['id'] ?>
//        }
//    });
</script>
</head>
<body>
<!-- loader -->
<div id="loader"><img src="images/loaders/1.gif" /><br />
Carregando...</div>
<div id="dark"></div>
<div class="total-container">
  <?php
    include ("header.php");
  ?>
<!-- body -->
  <div class="body-container">
  <?php
    if (isset($GET_service)) {
      $indexMode = true;
      include("./services/index.php"); 
    } else {
      include($GET_page.".php"); 
    }
    include ("footer.php");
  ?>
  </div>
</div>
<!-- Alerts -->
<div id="alert" class="dialog alert" >
  <div>
    <div id="alert-message" class="alert-message"></div>
    <div id="alert-buttons" class="alert-buttons"><input id="alert-confirm" class="button" type="button" value="Confirm"/></div>
  </div>
</div>
</body>
</html>
<!-- Tooltips -->
<div class="qtip qtip-stylename">
   <div class="qtip-tip" rel="cornerValue"></div>
   <div class="qtip-wrapper">
      <div class="qtip-borderTop"></div>
      <div class="qtip-contentWrapper">
         <div class="qtip-title">
            <div class="qtip-button"></div>
         </div>
         <div class="qtip-content"></div>
      </div>
      <div class="qtip-borderBottom"></div>
   </div>
</div>
<!-- This starts the page -->
<script type="text/javascript" src="js/common.js"></script>